package cn.huiyunche.admin.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.huiyunche.base.service.interfaces.VersionService;
import cn.huiyunche.base.service.model.SysVersionNote;
import cn.huiyunche.base.service.vo.Result;
import cn.huiyunche.tools.basic.exceptions.BusinessException;

@Controller
@RequestMapping("/version")
public class SysVersionNoteController {
	private static final Logger LOGGER = LoggerFactory.getLogger(SysVersionNoteController.class);
	
	@Autowired
	private VersionService versionService = null;
	
	private VersionService getVersionService() {
		return this.versionService;
	}
	
	/**
	 * 版本控制列表
	 * 
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public Result<List<SysVersionNote>> list() throws Exception{
		return this.getVersionService().list();
	}
	
	/**
	 * 版本数据增加、修改
	 * 
	 * @param versionNote
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "/modify", method = RequestMethod.POST)
	@ResponseBody
	public Result<Object> modifyVersion(SysVersionNote versionNote) throws Exception{
		LOGGER.info("modifyVersion params versionNode: {}", versionNote.toString());
		return this.getVersionService().modifyVersion(versionNote);
	}
	
	/**
	 * 删除版本数据
	 * 
	 * @param versionNote
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "/delversion", method = RequestMethod.POST)
	@ResponseBody
	public Result<Object> deleteVersion(Long id) throws Exception{
		LOGGER.info("deleteVersion params id: {}", id);
		return this.getVersionService().deleteVersion(id);
	}
	
	/**
	 * 根据ID查询版本信息
	 * 
	 * @param id
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "getbyid", method = RequestMethod.GET)
	@ResponseBody
	public Result<SysVersionNote> selectVersionId(Long id) throws Exception{
		Result<SysVersionNote> result = new Result<>(true, null, "查询成功");
		result.setData(this.getVersionService().selectVersionId(id));
		return result;
	}
}
